home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 090 / byt86oct.arc / ALLOC.ARC / ALLOC4.DEF < prev    next >
Text File  |  1985-07-12  |  2KB  |  43 lines

  1. DEFINITION MODULE Alloc4;
  2.  
  3. (* A safe storage allocator using the first-fit method and capabilities. 
  4.    Copyright 1986 by Jonathan Amsterdam.  All Rights Reserved. *)
  5.  
  6. FROM SYSTEM IMPORT WORD;
  7.  
  8. EXPORT QUALIFIED capability, blockSize, getWord, setWord, allocate, free,
  9.     getFreeList, resize, writeMap;
  10.  
  11. TYPE capability;    (* offset to a pointer, and generation count*)
  12.  
  13. PROCEDURE blockSize(c:capability):CARDINAL;
  14. (* Size of block *)
  15.  
  16. PROCEDURE getWord(c:capability; n:CARDINAL):WORD;
  17. (* Returns n'th word of block.  Block indexed from 0 to blockSize-1;
  18.    dies if n > blockSize-1. *)
  19.  
  20. PROCEDURE setWord(c:capability; n:CARDINAL; w:WORD);
  21. (* sets n'th word of block to w; dies if n > blockSize-1. *)
  22.  
  23. PROCEDURE allocate(nWords:CARDINAL):capability;
  24. (* allocates a block of nWords words (possibly slightly more, in some cases) *)
  25.  
  26. PROCEDURE free(VAR freeBlock:capability);
  27. (* frees block pointed to by freeBlock if it points into the heap, and sets 
  28.    freeBlock to NIL. *)
  29.  
  30. PROCEDURE resize(c:capability; nWords:CARDINAL);
  31. (* attempts to change size of block referenced by h *)
  32.  
  33. PROCEDURE writeMap;
  34. (* Writes, in order of address, the free and allocated blocks and their
  35.    sizes.  For debugging only; should be removed in "production" versions
  36.    of the allocator. *)
  37.  
  38. PROCEDURE getFreeList():capability;  (* really a blockPtr *)
  39. (* Returns a pointer to the free list.    For debugging only.  This should
  40.    be removed in "production" versions of the allocator. *)
  41.  
  42. END Alloc4.
  43. o the free list